public class Solution02 {
    // 全局变量
    private int sum;

    public int sumNumbers(TreeNode root){
        dfs(root, 0);
        return sum;
    }

    public void dfs(TreeNode root, int path){
        // 递归出口
        if(root.left == null && root.right == null){
            sum += (path * 10 + root.val);
            return ;
        }

        if(root.left != null){
            dfs(root.left, path * 10 + root.val);
        }
        if(root.right != null){
            dfs(root.right, path * 10 + root.val);
        }
    }
}
